package com.uni.action;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

/**
 * --------------project-------------
 *
 * @Author Unirithe  - Mr.Chao
 * - CSDN:
 * https://blog.csdn.net/Unirithe
 * - GitHub:
 * https://github.com/unirithe
 * @create 2021/12/18 14:17
 * ------------------------------------------
 */
@WebServlet(name="UserLoginOutServlet", urlPatterns = "/loginOut")
public class UserLoginOutAction extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        HttpSession session = req.getSession();
        Cookie[] cookies = req.getCookies();
        for (Cookie cookie : cookies) {
            cookie.setMaxAge(-1);
            cookie.setValue("");
            resp.addCookie(cookie);
        }
        session.invalidate(); // 注销 session
        resp.sendRedirect("code");
    }
}
